﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Easyui扩展库 Combobox - 落阳 整理</title>
    <link href="http://www.easyui-extlib.com/Content/Site.css" rel="stylesheet" />
    <script src="http://www.easyui-extlib.com/Scripts/jquery/jquery-1.11.0.min.js"></script>
    <script src="http://www.easyui-extlib.com/Scripts/jquery-extensions/jquery.jdirk.js"></script>
    <link href="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/themes/default/easyui.css" rel="stylesheet" />
    <link href="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/themes/icon.css" rel="stylesheet" />
    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/jquery.easyui.min.js"></script>
    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js"></script>

    <script src="http://www.easyui-extlib.com/Scripts/jquery-easyui-extensions/combobox/jeasyui.extensions.combobox.findItem.js"></script>
    <script>
        $(function () {

            var data = [
                { value: "1", text: "蜘蛛侠" },
                { value: "2", text: "蝙蝠侠" },
                { value: "3", text: "钢铁侠" },
                { value: "4", text: "神奇四侠" },
                { value: "5", text: "接盘侠" }
            ];
            $("#combobox1").combobox({
                valueField: "value",
                textField: "text",
                data: data,
                multiple: false,
                editable: false
            });

            $("#btnGet1").click(function () {
                var selected = $("#combobox1").combobox("findItem", "4");
                if (selected) {
                    alert(JSON.stringify(selected));
                }
                else { alert("未找到符合条件的项。"); }
            });

            $("#btnGet2").click(function () {
                var selected = $("#combobox1").combobox("findItem", function (item, index) { return item.value == "4" || item.value == "5"; });
                if (selected) {
                    alert(JSON.stringify(selected));
                }
                else { alert("未找到符合条件的项。"); }
            });

        });
    </script>
</head>
<body>
    <div class="easyui-panel" data-options="fit:true,border:false" style="padding:20px;">
        <input id="combobox1" type="text" value="" />
        <br />
        这是个 单选 的 combobox。
        <br /><br /><br />
        <a id="btnGet1" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 id 为 4 的一项，并输出其序列化结果</a>
        <br /><br /><br />
        <a id="btnGet2" class="easyui-linkbutton" data-options="iconCls:'icon-add'">获取 id 为 4或5 的一项，并输出其序列化结果</a>
    </div>
</body>
</html>
